{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>competition_time</th>\n",
       "      <th>净胜球</th>\n",
       "      <th>主客</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-06-30 22:00:00</td>\n",
       "      <td>0.405893</td>\n",
       "      <td>法国,阿根廷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-07-01 02:00:00</td>\n",
       "      <td>-0.408475</td>\n",
       "      <td>乌拉圭,葡萄牙</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-07-01 22:00:00</td>\n",
       "      <td>0.660441</td>\n",
       "      <td>西班牙,俄罗斯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-07-02 02:00:00</td>\n",
       "      <td>-0.044530</td>\n",
       "      <td>克罗地亚,丹麦</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-07-02 22:00:00</td>\n",
       "      <td>0.487959</td>\n",
       "      <td>巴西,墨西哥</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     competition_time       净胜球       主客\n",
       "0 2018-06-30 22:00:00  0.405893   法国,阿根廷\n",
       "1 2018-07-01 02:00:00 -0.408475  乌拉圭,葡萄牙\n",
       "2 2018-07-01 22:00:00  0.660441  西班牙,俄罗斯\n",
       "3 2018-07-02 02:00:00 -0.044530  克罗地亚,丹麦\n",
       "4 2018-07-02 22:00:00  0.487959   巴西,墨西哥"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "result_1 = pd.read_csv(r\"D:\\worldcup\\result_top8.csv\", encoding='gbk')\n",
    "result_2 = pd.read_csv(r\"D:\\worldcup\\result_top4.csv\", encoding='gbk')\n",
    "result_3 = pd.read_csv(r\"D:\\worldcup\\result.csv\", encoding='gbk')\n",
    "result_pro = pd.concat([result_1,result_2,result_3])\n",
    "\n",
    "result_pro['competition_time'] = pd.to_datetime(result_pro['competition_time'])\n",
    "result_pro = result_pro.reset_index(drop=True)\n",
    "\n",
    "result_pro['主客'] = result_pro['team1'].str.cat(result_pro['team2'], sep=',')\n",
    "\n",
    "result_pro = result_pro.drop(['team1','team2'], axis=1).reset_index(drop=True)\n",
    "result_pro.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>赛事</th>\n",
       "      <th>时间</th>\n",
       "      <th>主队</th>\n",
       "      <th>主</th>\n",
       "      <th>和</th>\n",
       "      <th>客</th>\n",
       "      <th>客队</th>\n",
       "      <th>比分</th>\n",
       "      <th>真实净胜球</th>\n",
       "      <th>主客</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>世界杯分</td>\n",
       "      <td>2018-06-29 02:00:00</td>\n",
       "      <td>英格兰</td>\n",
       "      <td>2.551</td>\n",
       "      <td>2.936</td>\n",
       "      <td>3.273</td>\n",
       "      <td>比利时</td>\n",
       "      <td>0:01</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>英格兰,比利时</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>世界杯分</td>\n",
       "      <td>2018-06-29 02:00:00</td>\n",
       "      <td>巴拿马</td>\n",
       "      <td>4.170</td>\n",
       "      <td>3.577</td>\n",
       "      <td>1.923</td>\n",
       "      <td>突尼斯</td>\n",
       "      <td>1:02</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>巴拿马,突尼斯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>世界杯分</td>\n",
       "      <td>2018-06-28 22:00:00</td>\n",
       "      <td>塞内加尔</td>\n",
       "      <td>4.710</td>\n",
       "      <td>3.607</td>\n",
       "      <td>1.809</td>\n",
       "      <td>哥伦比亚</td>\n",
       "      <td>0:01</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>塞内加尔,哥伦比亚</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>世界杯分</td>\n",
       "      <td>2018-06-28 22:00:00</td>\n",
       "      <td>日本</td>\n",
       "      <td>3.062</td>\n",
       "      <td>3.165</td>\n",
       "      <td>2.577</td>\n",
       "      <td>波兰</td>\n",
       "      <td>0:01</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>日本,波兰</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>世界杯分</td>\n",
       "      <td>2018-06-28 02:00:00</td>\n",
       "      <td>瑞士</td>\n",
       "      <td>1.629</td>\n",
       "      <td>3.597</td>\n",
       "      <td>6.872</td>\n",
       "      <td>哥斯达黎加</td>\n",
       "      <td>2:02</td>\n",
       "      <td>0.0</td>\n",
       "      <td>瑞士,哥斯达黎加</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     赛事                  时间    主队      主      和      客     客队    比分  真实净胜球  \\\n",
       "0  世界杯分 2018-06-29 02:00:00   英格兰  2.551  2.936  3.273    比利时  0:01   -1.0   \n",
       "1  世界杯分 2018-06-29 02:00:00   巴拿马  4.170  3.577  1.923    突尼斯  1:02   -1.0   \n",
       "2  世界杯分 2018-06-28 22:00:00  塞内加尔  4.710  3.607  1.809   哥伦比亚  0:01   -1.0   \n",
       "3  世界杯分 2018-06-28 22:00:00    日本  3.062  3.165  2.577     波兰  0:01   -1.0   \n",
       "4  世界杯分 2018-06-28 02:00:00    瑞士  1.629  3.597  6.872  哥斯达黎加  2:02    0.0   \n",
       "\n",
       "          主客  \n",
       "0    英格兰,比利时  \n",
       "1    巴拿马,突尼斯  \n",
       "2  塞内加尔,哥伦比亚  \n",
       "3      日本,波兰  \n",
       "4   瑞士,哥斯达黎加  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import re\n",
    "\n",
    "result_group = pd.read_csv(r\"D:\\worldcup\\world_cup.csv\", encoding='gbk')\n",
    "result_group['时间'] = pd.to_datetime(result_group['时间'])\n",
    "result_group['主'] = [float(re.search(r'^[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*$', x).group()) for x in result_group['主']]\n",
    "result_group['和'] = [float(re.search(r'^[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*$', x).group()) for x in result_group['和']]\n",
    "result_group['客'] = [float(re.search(r'^[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*$', x).group()) for x in result_group['客']]\n",
    "result_group['真实净胜球'] = [float(x.split(':')[0])-float(x.split(':')[1]) for x in result_group['比分']]\n",
    "result_group['主客'] = result_group['主队'].str.cat(result_group['客队'], sep=',')\n",
    "result_group.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "result_all = pd.merge(result_pro, result_group, on = '主客')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>foul</th>\n",
       "      <th>home_team</th>\n",
       "      <th>most</th>\n",
       "      <th>pass</th>\n",
       "      <th>pass_rate</th>\n",
       "      <th>possession</th>\n",
       "      <th>red_card</th>\n",
       "      <th>result</th>\n",
       "      <th>score</th>\n",
       "      <th>shot</th>\n",
       "      <th>team_id</th>\n",
       "      <th>team_name</th>\n",
       "      <th>time</th>\n",
       "      <th>type</th>\n",
       "      <th>visiting_team</th>\n",
       "      <th>yellow_card</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>英格兰</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>英格兰</td>\n",
       "      <td>2018-06-29 02:00:00</td>\n",
       "      <td>世界杯分</td>\n",
       "      <td>比利时</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>巴拿马</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>巴拿马</td>\n",
       "      <td>2018-06-29 02:00:00</td>\n",
       "      <td>世界杯分</td>\n",
       "      <td>突尼斯</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>NaN</td>\n",
       "      <td>塞内加尔</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>塞内加尔</td>\n",
       "      <td>2018-06-28 22:00:00</td>\n",
       "      <td>世界杯分</td>\n",
       "      <td>哥伦比亚</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>日本</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>日本</td>\n",
       "      <td>2018-06-28 22:00:00</td>\n",
       "      <td>世界杯分</td>\n",
       "      <td>波兰</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>瑞士</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>瑞士</td>\n",
       "      <td>2018-06-28 02:00:00</td>\n",
       "      <td>世界杯分</td>\n",
       "      <td>哥斯达黎加</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   foul home_team  most pass  pass_rate  possession  red_card result  score  \\\n",
       "0   NaN       英格兰   NaN  NaN        NaN         NaN       NaN   0-01    NaN   \n",
       "1   NaN       巴拿马   NaN  NaN        NaN         NaN       NaN   1-02    NaN   \n",
       "2   NaN      塞内加尔   NaN  NaN        NaN         NaN       NaN   0-01    NaN   \n",
       "3   NaN        日本   NaN  NaN        NaN         NaN       NaN   0-01    NaN   \n",
       "4   NaN        瑞士   NaN  NaN        NaN         NaN       NaN   2-02    NaN   \n",
       "\n",
       "  shot  team_id team_name                 time  type visiting_team  \\\n",
       "0  NaN      NaN       英格兰  2018-06-29 02:00:00  世界杯分           比利时   \n",
       "1  NaN      NaN       巴拿马  2018-06-29 02:00:00  世界杯分           突尼斯   \n",
       "2  NaN      NaN      塞内加尔  2018-06-28 22:00:00  世界杯分          哥伦比亚   \n",
       "3  NaN      NaN        日本  2018-06-28 22:00:00  世界杯分            波兰   \n",
       "4  NaN      NaN        瑞士  2018-06-28 02:00:00  世界杯分         哥斯达黎加   \n",
       "\n",
       "   yellow_card  \n",
       "0          NaN  \n",
       "1          NaN  \n",
       "2          NaN  \n",
       "3          NaN  \n",
       "4          NaN  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "historical_record = pd.read_csv(r\"D:\\worldcup\\historical_record.csv\")\n",
    "del historical_record['id']\n",
    "del historical_record['create_time']\n",
    "del historical_record['update_time']\n",
    "historical_record = historical_record.drop_duplicates() \n",
    "\n",
    "historical_group = result_group.rename(columns={'主队':'home_team', '客队':'visiting_team', '赛事':'type', '时间':'time', '比分':'result'}).loc[:, ['home_team', 'visiting_team', 'type', 'time', 'result']]\n",
    "historical_group['result'] = historical_group['result'].str.replace(':', '-')\n",
    "historical_group['team_name'] = historical_group['home_team']\n",
    "historical_group1 = pd.DataFrame(historical_group.values, columns=['home_team', 'visiting_team', 'type', 'time', 'result', 'team_name'])\n",
    "historical_group['team_name'] = historical_group['visiting_team']\n",
    "historical_group2 = pd.DataFrame(historical_group.values, columns=['home_team', 'visiting_team', 'type', 'time', 'result', 'team_name'])\n",
    "\n",
    "historical_record_group = pd.concat([historical_group1, historical_group2, historical_record])\n",
    "\n",
    "historical_record_group.to_csv(r\"D:\\worldcup\\historical_record_group_top8_top4.csv\", index=False)\n",
    "historical_record_group.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import datetime\n",
    "import numpy as np\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "alg = LinearRegression()\n",
    "alg.fit(np.array(result_all['净胜球']).reshape(-1, 1), np.array(result_all['真实净胜球']).reshape(-1, 1))\n",
    "\n",
    "def sigmoid(inX):  \n",
    "    return 1.0/(1+np.exp(-inX))  \n",
    "\n",
    "def goal_fiff(team1, team2, competition_time):\n",
    "    #historical_record = pd.read_csv(r\"D:\\worldcup\\historical_record.csv\")\n",
    "    historical_record = pd.read_csv(r\"D:\\worldcup\\historical_record.csv\")\n",
    "    del historical_record['id']\n",
    "    del historical_record['create_time']\n",
    "    del historical_record['update_time']\n",
    "    #去重\n",
    "    historical_record = historical_record.drop_duplicates().reset_index(drop = True)\n",
    "    #处理result为净胜球    \n",
    "    for i in range(len(historical_record)):\n",
    "        num1 = historical_record.loc[i, 'result'].split('-')[0]\n",
    "        num2 = historical_record.loc[i, 'result'].split('-')[1]\n",
    "        if historical_record.loc[i, 'home_team'] == historical_record.loc[i, 'team_name']:\n",
    "            historical_record.loc[i, 'result'] = int(num1) - int(num2)\n",
    "        else:\n",
    "            historical_record.loc[i, 'result'] = int(num2) - int(num1)\n",
    "    #选出team1和team2\n",
    "    historical_record_1 = historical_record.loc[historical_record[\"team_name\"] == team1]\n",
    "    historical_record_2 = historical_record.loc[historical_record[\"team_name\"] == team2]\n",
    "    e_df = set(historical_record_1['home_team'].tolist()).union(set(historical_record_1['visiting_team'].tolist()))\n",
    "    s_df = set(historical_record_2['home_team'].tolist()).union(set(historical_record_2['visiting_team'].tolist()))\n",
    "    e_union_s = e_df.intersection(s_df)\n",
    "    #print(e_union_s)\n",
    "    #选出即和team1交手又和team2交手的队伍\n",
    "    int_inf_2 = historical_record_2.loc[historical_record_2[\"visiting_team\"].isin(e_union_s) | historical_record_2[\"home_team\"].isin(e_union_s)]\n",
    "    int_inf_1 = historical_record_1.loc[historical_record_1[\"visiting_team\"].isin(e_union_s) | historical_record_1[\"home_team\"].isin(e_union_s)]\n",
    "    concat_e_s = pd.concat([int_inf_1, int_inf_2]).reset_index(drop=True)  \n",
    "    \n",
    "    #print(e_df)\n",
    "    #设置比赛开始时间\n",
    "    concat_e_s_sle = concat_e_s.loc[: , ['team_name', 'home_team', 'visiting_team', 'time', 'result', 'score']]\n",
    "    concat_e_s_sle['time'] = pd.to_datetime(concat_e_s_sle['time'])\n",
    "    start_date_str = competition_time\n",
    "    start_date = datetime.datetime.strptime(start_date_str, '%Y/%m/%d %H:%M')\n",
    "    #sigmode处理时间，得出权重\n",
    "    concat_e_s_sle['sec_from_start_to_data'] = (concat_e_s_sle.loc[:, 'time']-start_date).dt.total_seconds()  \n",
    "    concat_e_s_sle['sfstd_non'] = concat_e_s_sle.loc[:, ['sec_from_start_to_data']].apply(lambda x: (x - np.mean(x)) / (np.std(x)))\n",
    "\n",
    "    concat_e_s_sle['wight'] = sigmoid(concat_e_s_sle['sfstd_non'])\n",
    "    #净胜球与权重结合\n",
    "    concat_e_s_sle['result_wight'] = concat_e_s_sle['result'] * concat_e_s_sle['wight']\n",
    "    #计算结合平均值\n",
    "    union_1 = pd.DataFrame({'team_name':[],'oppose_team':[],'mean_result_1':[]})\n",
    "    union_2 = pd.DataFrame({'team_name':[],'oppose_team':[],'mean_result_2':[]})\n",
    "    for i in e_union_s:\n",
    "        if i != team1:\n",
    "            mean_1 = concat_e_s_sle.loc[(concat_e_s_sle['team_name'] == team1)&((concat_e_s_sle['home_team'] == i) | (concat_e_s_sle['visiting_team'] == i))].loc[:, 'result_wight'].mean()\n",
    "            union_1 = pd.concat([union_1, pd.DataFrame({'team_name':[team1],'oppose_team':[i],'mean_result_1':[mean_1]})])\n",
    "        if i != team2:\n",
    "            mean_2 = concat_e_s_sle.loc[(concat_e_s_sle['team_name'] == team2)&((concat_e_s_sle['home_team'] == i) | (concat_e_s_sle['visiting_team'] == i))].loc[:, 'result_wight'].mean()\n",
    "            union_2 = pd.concat([union_2, pd.DataFrame({'team_name':[team2],'oppose_team':[i],'mean_result_2':[mean_2]})])\n",
    "        \n",
    "        \n",
    "    union = union_1.merge(union_2, on = 'oppose_team')\n",
    "    #print(union)\n",
    "    \n",
    "    #team1与team2直接对抗结果\n",
    "    mean_1_2 = concat_e_s_sle.loc[(concat_e_s_sle['team_name'] == team1)&((concat_e_s_sle['home_team'] == team2) | (concat_e_s_sle['visiting_team'] == team2))].loc[:, 'result_wight'].mean()\n",
    "    op_1_2 = pd.DataFrame({'team_name':[team1],'oppose_team':[team2],'mean_result_1':[mean_1_2]})\n",
    "    mean_2_1 = concat_e_s_sle.loc[(concat_e_s_sle['team_name'] == team2)&((concat_e_s_sle['home_team'] == team1) | (concat_e_s_sle['visiting_team'] == team1))].loc[:, 'result_wight'].mean()\n",
    "    op_2_1 = pd.DataFrame({'team_name':[team2],'oppose_team':[team1],'mean_result_2':[mean_2_1]})\n",
    "    #合并所有\n",
    "    union_all = pd.concat([union, op_2_1, op_1_2]).fillna(0)\n",
    "    #print(pd.concat([union, op_2_1, op_1_2]).fillna(0))\n",
    "    \n",
    "    res = (union_all['mean_result_1'] - union_all['mean_result_2']).mean()\n",
    "    #修改\n",
    "    #res = alg.predict(np.array(res).reshape(-1, 1))[0,0]\n",
    "    res_e_s = pd.DataFrame({'team1':[team1], 'team2':[team2], 'competition_time':[competition_time], '净胜球':[res]})\n",
    "    return res_e_s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>competition_time</th>\n",
       "      <th>team1</th>\n",
       "      <th>team2</th>\n",
       "      <th>净胜球</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018/7/11 2:00</td>\n",
       "      <td>法国</td>\n",
       "      <td>比利时</td>\n",
       "      <td>0.308212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018/7/12 2:00</td>\n",
       "      <td>克罗地亚</td>\n",
       "      <td>英格兰</td>\n",
       "      <td>0.019305</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  competition_time team1 team2       净胜球\n",
       "0   2018/7/11 2:00    法国   比利时  0.308212\n",
       "0   2018/7/12 2:00  克罗地亚   英格兰  0.019305"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "competition_process = pd.read_csv(r\"D:\\worldcup\\competition_process_2.csv\", encoding='gbk', names =['competition_time','team1', 'vs', 'team2'])\n",
    "competition_process['team1'] = [x.strip() for x in competition_process['team1']]\n",
    "competition_process['team2'] = [x.strip() for x in competition_process['team2']]\n",
    "del competition_process['vs']\n",
    "\n",
    "result = pd.DataFrame({'team1':[] , 'team2':[], 'competition_time':[], '净胜球':[]})\n",
    "for i in range(len(competition_process)):\n",
    "    result = pd.concat([result, goal_fiff(competition_process.loc[i, 'team1'], competition_process.loc[i, 'team2'], competition_process.loc[i, 'competition_time'])])\n",
    "    #print(i)\n",
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
